package org.emcode.sample.appleguice.client;


import org.emcode.sample.appleguice.client.gin.AppleGuiceInjector;
import org.emcode.sample.appleguice.client.mvp.AppPresenter;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class AppleGuice implements EntryPoint {
	
	/*
	 * Create a GIN injector: a GWT client-friendly dependency injection utility
	 * based on Guice (which is used on the server). Here we create a deferred
	 * binding (ie, compile-time dynamic binding) to the injector.
	 * 
	 * Check out the AppleGuiceInjector to see what it does.
	 */
	private final AppleGuiceInjector injector = GWT.create(AppleGuiceInjector.class);
	
	public void onModuleLoad() {
		
		Log.info("AppleGuice onModuleLoad");
		
		/*
		 * The AppPresenter is the main Presenter for our entire application.
		 * It is fetched from the injector interface after being bound in the
		 * AppleGuiceClientModule {bind(AppPresenter.class).in(Singleton.class);}
		 * So our application has exactly one AppPresenter on the client.
		 */
		final AppPresenter appPresenter = injector.getAppPresenter();
		
		/*
		 * Here we pass the RootPanel singleton into the AppPresenter, which
		 * remembers the RootPanel as the container, then clears the RootPanel,
		 * then adds a GreetingPresenter as the main widget for the application.
		 */
		appPresenter.go(RootPanel.get());
		
		/*
		 * We also fetch a PlaceManager (a manager for the History feature) and 
		 * mark the application history (which on the first hit happens to be 
		 * nothing special, but later on might just be)
		 */
		injector.getPlaceManager().fireCurrentPlace();
		
	}
}